import Vue from 'vue'
import Vuex from 'vuex'
import menu from './modules/menu/index'
import role from './modules/role/index'
import user from './modules/user/index'
import sort from './modules/sort/index'
import specs from './modules/goodsspecs/index'
import goods from './modules/goods/index'
import member from './modules/member/index'
import banner from './modules/banner/index'
import seck from './modules/seck/index'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo:sessionStorage.getItem('userinfo') ? JSON.parse(sessionStorage.getItem('userinfo')) : null
  },
  getters: {
    getUser(state){
      return state.userInfo
    }
  },
  mutations: {
    CHANGEUSER(state,payload){
      if(payload){
        state.userInfo = payload
        sessionStorage.setItem('userinfo',JSON.stringify(payload))
      }else{
        sessionStorage.removeItem('userinfo')
      }
      
    }
  },
  actions: {
    changeuserInfo({commit},payload){
      commit('CHANGEUSER',payload)
    }
  },
  modules: {
    menu,
    role,
    user,
    sort,
    specs,
    goods,
    member,
    banner,
    seck
  }
})
